package com.open.capacity.reimburse.controller;

import java.util.Map;

import com.open.capacity.commons.Result;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.reimburse.entity.ImpKjpz;
import com.open.capacity.reimburse.service.ImpKjpzService;

import com.open.capacity.commons.PageResult;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * 数据导入-会计凭证
 *
 * @author
 * @email
 * @date 2021-11-16 09:52:14
 */
@RestController
@RequestMapping("impkjpzs")
@Api(tags = "数据导入-会计凭证")
public class ImpKjpzController {

    @Autowired
    private ImpKjpzService impKjpzService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('imp_kjpz:impkjpz:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = impKjpzService.pageAll(params);
        return pageResult;
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('imp_kjpz:impkjpz:save')")
    public Result save(@RequestBody @Valid ImpKjpz impKjpz, Integer keyValue) {
        if (keyValue != null) {
            impKjpzService.save(impKjpz);
        } else {
            impKjpz.setId(keyValue);
            impKjpzService.update(impKjpz);
        }
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('imp_kjpz:impkjpz:delete')")
    public Result delete(@PathVariable String id) {
        impKjpzService.delete(id);
        return Result.succeed("删除成功");
    }

    /**
     * 导入excel
     */
    @PostMapping("/importExcel")
    @PreAuthorize("hasAnyAuthority('imp_kjpz:impkjpz:import')")
    public Result importExcel(@RequestParam("file") MultipartFile multipartFile) throws Exception {
        long count = impKjpzService.importExcel(multipartFile);
        return Result.succeed(count, "导入成功");
    }

}
